<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
        <div style="text-align: center">
            <button id="ok" type="button" class="layui-btn layui-btn-normal">确定</button>
        </div>


    </div>
</div>
<script src="../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        //用户id
        var userId = window.userId;

        table.render({
            elem: '#currentTableId',
            url: '../../user/selectAssignRole?userId=' + userId,
            defaultToolbar: [],
            cols: [[
                {type: "checkbox", fixed: "left"},
                {field: 'id', title: 'ID', sort: true},
                {field: 'name', title: '角色昵称'},
                {field: 'code', title: '角色编码'}
            ]]/*,
            limits: [20, 25, 50, 100],
            limit: 20,
            page: true*/
        });

        $("#ok").click(function () {
            var checkStatus = table.checkStatus('currentTableId')
            var data = checkStatus.data;
            if (data.length == 0){
                layer.msg("请选择角色");
                return;
            }

            var roleIdArray = new Array();
            for (var i = 0; i<data.length;i++ ){
                //角色id
                roleIdArray.push(data[i].id);
            }

            $.post('../../user/assignRole',{userId:userId,roleIds:JSON.stringify(roleIdArray)},function (data) {
                //关闭窗口
                var iframeIndex = parent.layer.getFrameIndex(window.name);
                parent.layer.close(iframeIndex);

            },'json');

        });


    });
</script>
<script>

</script>

</body>
</html>